import {isEmpty, resetState} from '@/utils/index';
import {mapState, mapGetters, mapMutations, mapActions} from 'vuex';

/*
页面的混合
 */
var messageBadgeEvent = {
    data(){
        return {
        }
    },
    methods:{
        ...mapMutations({
            updateStoreBadge:'user/updateBadge'
        }),
        clickMessage(){
            uni.$emit('clearBadge'); 
            uni.navigateTo({
				url: '/pages/message/inMsgList'
            });
        },
        updateBadge({value='0'}){
			console.log('receive addBadge')
			if(value!='0'){
                this.currentWebView.setTitleNViewButtonBadge({  
					index: this.messageBadgeIndex,  
					text: `${value}`,  
				}); 
            }
            else if(value=='0'){
                // #ifdef APP-PLUS  
                this.currentWebView.removeTitleNViewButtonBadge({
                    index: this.messageBadgeIndex,  
                });
                // #endif
			}
			/*
			更新badge
            */
            if(value!=this.messageBadge){
                this.updateStoreBadge({badgeText:value}) 
            }
		}
    },
    computed:{
		messageBadge(){
            console.log('this.userData:',this.userData)
			return this.userData.badgeText;
		}
	},
    // 我的页面  
    onLoad(){  
        // 监听事件  
        uni.$on('onUpdateBadge',(payload)=>{  
            console.log('on addBadge')
            this.updateBadge(payload)
        });
    },  
    onReady(){
        // #ifdef APP-PLUS
        console.log('messageBadge:',this.messageBadge)
        if(this.messageBadge!=''&&this.messageBadge!=undefined){
            this.currentWebView.setTitleNViewButtonBadge({  
                index: this.messageBadgeIndex,  
                text: `${this.messageBadge}`,  
            });  
        }
        // #endif
    },
    onUnload() {  
        // 移除监听事件  
        uni.$off('onUpdateBadge');  
        },  
};
export default messageBadgeEvent;